<?php
declare (strict_types = 1);

namespace app\common\model;

use think\facade\Db;
use think\Model;
use think\facade\Session;
use think\model\concern\SoftDelete;

class GmTglogs extends Model
{
    use SoftDelete;
     protected $deleteTime = false;
     
    public static function get1List()
    {
        
        $where = [];
        $limit = input('get.limit');

        // 如果不是超级管理员，添加限制条件
        if (Session::get('admin.id') != '1') {
            $where[] = ['b.id', '=', Session::get('admin.id')];
        }
        
        //按推广人员唯一编码查找
        if ($rlink = input("rlink")) {
            $where[] = ["b.rlink", "like", "%" . $rlink . "%"];
        }
        //按玩家账号查找
        if ($baccount = input("baccount")) {
            $where[] = ["a.baccount", "like", "%" . $baccount . "%"];
        }

        // 构建 SQL 查询语句
        $sql = Db::table('gm_tglogs')
            ->alias('a')
            ->join('admin_admin b', 'a.acode = b.rlink')
            ->field(' b.id AS uid,a.baccount AS baccount, a.bregtime AS regtime, b.rlink AS rlink, b.nickname AS nickname ')
            ->where($where)
            ->order('a.bregtime', 'desc')
            ->paginate($limit);

        return ['code' => 0, 'data' => $sql->items(), 'extend' => ['count' => $sql->total(), 'limit' => $limit]];
    }
  
    
}
